<?php

/**
 * OffersModel 模型
 * Class UserModel
 */
class UserModel extends BaseModel
{

    public $tableName = "user";
    public $errMsg = '';

    public $ruser;

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'user_type' => $data['user_type'],
                'open_id'   => $data['open_id'],
                'unionid'   => $data['unionid'],
                'refer_user_id' => $data['refer_user_id'],
                'shop_user_id'  => isset($data['shop_user_id'])?$data['shop_user_id']: 0,
                'refer_num' => 0,
                'shop_id'   => $data['shop_id'],
                'head_img'  => $data['head_img'],
                'wxcity'    => $data['wxcity'],
                'moble'     => $data['moble'],
                'nick_name' => $data['nick_name'],
                'login_pwd' => $data['login_pwd'],
                'point'     => 0,
                'f_point'   => 0,
                'sex'       => 0,
                'use_money_total'   => 0,
                'status'    => 1,
                'create_time'=> time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }
}